//queue.js
const app=getApp();

Page({
  data:{
    queueList:null,
    navbarData: {
      backHome: false,
      showCapsule: false, //是否显示左上角图标   1表示显示    0表示不显示
      title: '选择队列', //导航栏 中间的标题
    },
    navHeight: app.globalData.statusBarHeight * 2 + 86,
    defaultIcon:"/image/defaultQueueIcon.png",

    xieyi:true,
  },
  //选取符合条件的分类，跳转到后端
  onLoad(options){
    const tongyi = wx.getStorageSync('tongyi')
    if (tongyi && tongyi == 1) {
      this.setData({
        xieyi:false
      })
      this.asdc(options)
    }

  },
  tongyi:function(options){
    // wx.setStorageSync('tongyi', 1)
    // this.setData({
    //   xieyi:false
    // })
    // this.asdc(options)

    wx.navigateTo({
      // url: "/pages/guide/consent/consent?url=" + e.currentTarget.dataset.url
      url: "../guide_page/guide_page"
    })
  },

  asdc:function(options){
    var that = this;
    let showBack;
    if(options){
      showBack = options.code;
    }else{
      showBack = false;
    }
    this.setData({
      navbarData: {
        backHome: showBack,
        title: '选择队列', //导航栏 中间的标题
      }
    })
    wx.request({
      url: app.getUrl('/xcx/queryQueue'),
      method: 'GET',
      header: wx.getStorageSync('cookie'),
      success(res) {

        if (res.data.code == 0) {
          if(res.data.data.length == 1) {
            var queue = res.data.data[0];
            // let userId =app.globalData.userId
            // const {  tenantId } = app.globalData.userList.filter(item=>{
            //     return item.id == userId
            // })[0];
            let newSurvey = app.globalData.hospitalInfo?.remark1
            console.log('newSurvey1',newSurvey)
            
            if(newSurvey==1){
                let url = "/H5/view-html/scale/html/index.html#/newArchive"
                app.globalData.templId = queue.clientTemplId
                wx.navigateTo({
                    url: `../../advertise/advertise?url=${url}&templId=${queue.clientTemplId }&queueId=${queue.id}`
                  })
            }else{
                wx.navigateTo({
                    url: "../../archive/newArchive?templId=" + queue.clientTemplId + "&queueId=" + queue.id,
                  })
            }
               

          }
          // var queueArr = []
          // res.data.data.forEach((item,index,arr)=>{
          //   if(item.queueName=="低危早产儿队列" ||item.queueName=="神经系统疾患患者管理" ||item.queueName=="先天性胸腹腔及胸腹腔内脏结构异常队列"||item.queueName=="支气管肺发育不良队列" ){
          //     queueArr.push(item)
          //   }
          // })

          that.setData({
            queueList: res.data.data
          })
        }else{
          wx.showToast({
            title: '微信登录超时或未选择科室',
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },




  toAddPt : function(e){
    console.log('e.currentTarget.dataset.queueid',e.currentTarget.dataset.queueid)
    app.globalData.queueId=e.currentTarget.dataset.queueid
    let newSurvey = app.globalData.hospitalInfo?.remark1
    console.log('newSurvey',newSurvey)
    console.log('app',this.data.queueList)
    
    if(newSurvey==1){
        let url = "/H5/view-html/scale/html/index.html#/newArchive"
        wx.navigateTo({
            url: `../../advertise/advertise?url=${url}&templId=${e.currentTarget.dataset.templid }&queueId=${ e.currentTarget.dataset.queueid}`
          })
    }else{
        wx.navigateTo({
            url: "../../archive/newArchive?templId=" + e.currentTarget.dataset.templid + "&queueId=" + e.currentTarget.dataset.queueid,
          })
    }
    // wx.navigateTo({
    //   url: "../../archive/newArchive?templId=" + e.currentTarget.dataset.templid + "&queueId=" + e.currentTarget.dataset.queueid,
    // })
  },
  toIndex:function(){
    wx.switchTab({
      url: '../../index/index',
    })
  }
})